/*******************************************************************
 *
 * Copyright (C), 2021-2022, LS, All rights reserved.
 *
 * Author      : 
 * Create Time : 2021-09-17
 * Version     : v0.1
 * Description : 
 *******************************************************************/
 
#ifndef _LS_BLE_SDK_CONFIG_H_
#define _LS_BLE_SDK_CONFIG_H_

/*----------------------------Head file----------------------------*/
#include "stdint.h"
#include "user_config.h"

/*----------------------------macro file---------------------------*/
#if(DEBUG_INFO)
#define LS_BLE_LOG_ENABLE       1
#else
#define LS_BLE_LOG_ENABLE       0
#endif

#define LS_BLE_FILE_SVC_ENABLE  1

/************************Flash area Macro*******************************/

#define LS_BLE_FLASH_SECTOR_SIZE    0x1000

//#define FLASH_BASE_ADDR         (0x11000000)

//Flash Api include FLASH_BASE_ADDR offset
#define APP_IMG_MAX_SIZE    		(1024*144)

#define APP_BANK_BIN_ADDR           0x11000
#define APP_BANK_BIN_END_ADDR       (APP_BANK_BIN_ADDR + APP_IMG_MAX_SIZE)
#define OTA_IMG_START_ADDR          APP_BANK_BIN_END_ADDR
#define OTA_IMG_END_ADDR            (OTA_IMG_START_ADDR + APP_IMG_MAX_SIZE)

//User store part
#define USER_STORE_START_ADDR       0x59000     //156K
#define USER_STORE_END_ADDR         0x80000

#if (OTA_IMG_END_ADDR > USER_STORE_START_ADDR)
#error "Err ota flash addr definition"
#endif

/************************BLE Param macro*******************************/

#define BLE_MTU_MAX_SIZE                247

//BLE advertisement info
#define BLE_ADV_FAST_INV_MS             500     //range: 20~10240ms
#define BLE_ADV_SLOW_INV_MS             1000    //range: 20~10240ms
#define BLE_ADV_DEV_NAME                "JC-2A"
#define BLE_ADV_DEV_NAME_LEN            (sizeof(BLE_ADV_DEV_NAME)-1)

//BLE connection info
#define BLE_CONN_INTERVAL_MIN           24
#define BLE_CONN_INTERVAL_MAX           36
#define BLE_SLAVE_LATENCY               2
#define BLE_CONN_SUP_TIMEOUT            300

//BLE device info
#define MANUFAC_NAME_STR                "Jumpcol"
#if (PROJECT_NUM == JC_1)
#define MODULE_NUM_STR                  "JC-1"
#elif (PROJECT_NUM == JRS_2102)
#define MODULE_NUM_STR                  "JRS_2102"
#else
#error "MODULE_NUM_STR is not valid."
#endif
#define HARDWARE_VER_STR                "1.0.1"
#define SOFTWARE_VER_STR                "1.0.1"
#define FIRMWARE_VER_STR                "1.0.15"

//APP protocol

#if(LEIJISHU == 0)

#define ADV_INIT_MANU_DATA_HEAD         CUS_PRO_HEAD_B1, CUS_PRO_VER_B2
#define ADV_INIT_MANU_DATA_MAC          0,0,0,0,0,0
#define ADV_INIT_MANU_DATA_MODE         0
#define ADV_INIT_MANU_DATA_SET          0,0
#define ADV_INIT_MANU_DATA_UTC          0,0,0,0
#define ADV_INIT_MANU_DATA_SKIP_SEC     0,0
#define ADV_INIT_MANU_DATA_SKIP_CNT     0,0
#define ADV_INIT_MANU_DATA_SKIP_VLD_SEC 0,0

#if(SCHOOL_SKIP_ENABLE)
#define ADV_INIT_MANU_DATA_SCHOOL       0,0,0,0,0,0

#if(SCHOOL_ADV_ENABLE)
#define ADV_SCOOL_DATA_LEN              6
#else
#define ADV_SCOOL_DATA_LEN              0
#endif  //#if(SCHOOL_ADV_ENABLE)

#else
#define ADV_SCOOL_DATA_LEN              0
#endif
#if(DEV_MAC_BURN_ENABLE)
#define ADV_INIT_MAC_VALID              0
#if(SCHOOL_SKIP_ENABLE)

#if(SCHOOL_ADV_ENABLE)
#define ADV_INIT_MANU_COMPANY_DATA      ADV_INIT_MANU_DATA_HEAD, ADV_INIT_MANU_DATA_MAC, ADV_INIT_MANU_DATA_MODE, ADV_INIT_MANU_DATA_SET, ADV_INIT_MANU_DATA_UTC, ADV_INIT_MANU_DATA_SKIP_SEC, ADV_INIT_MANU_DATA_SKIP_CNT, ADV_INIT_MANU_DATA_SKIP_VLD_SEC, ADV_INIT_MAC_VALID, ADV_INIT_MANU_DATA_SCHOOL
#else
#define ADV_INIT_MANU_COMPANY_DATA      ADV_INIT_MANU_DATA_HEAD, ADV_INIT_MANU_DATA_MAC, ADV_INIT_MANU_DATA_MODE, ADV_INIT_MANU_DATA_SET, ADV_INIT_MANU_DATA_UTC, ADV_INIT_MANU_DATA_SKIP_SEC, ADV_INIT_MANU_DATA_SKIP_CNT, ADV_INIT_MANU_DATA_SKIP_VLD_SEC, ADV_INIT_MAC_VALID
#endif  //#if(SCHOOL_ADV_ENABLE)

#else
#define ADV_INIT_MANU_COMPANY_DATA      ADV_INIT_MANU_DATA_HEAD, ADV_INIT_MANU_DATA_MAC, ADV_INIT_MANU_DATA_MODE, ADV_INIT_MANU_DATA_SET, ADV_INIT_MANU_DATA_UTC, ADV_INIT_MANU_DATA_SKIP_SEC, ADV_INIT_MANU_DATA_SKIP_CNT, ADV_INIT_MANU_DATA_SKIP_VLD_SEC, ADV_INIT_MAC_VALID
#endif
#define ADV_MANUFACTORY_DATA_LEN        (22+1+ADV_SCOOL_DATA_LEN)
#else
#define ADV_INIT_MANU_COMPANY_DATA      ADV_INIT_MANU_DATA_HEAD, ADV_INIT_MANU_DATA_MAC, ADV_INIT_MANU_DATA_MODE, ADV_INIT_MANU_DATA_SET, ADV_INIT_MANU_DATA_UTC, ADV_INIT_MANU_DATA_SKIP_SEC, ADV_INIT_MANU_DATA_SKIP_CNT, ADV_INIT_MANU_DATA_SKIP_VLD_SEC
#define ADV_MANUFACTORY_DATA_LEN        (21+1)
#endif

#else   //#if(LEIJISHU == 0)

#define ADV_HEAD_B1                     0xFC
#define ADV_VER_B2                      0xA2

#define ADV_INIT_MANU_DATA_HEAD         ADV_HEAD_B1, ADV_VER_B2
#define ADV_INIT_MANU_DATA_MAC          0,0,0,0,0,0
#define ADV_INIT_MANU_DATA_MODE         0
#define ADV_INIT_MANU_DATA_SET          0,0
#define ADV_INIT_MANU_DATA_UTC          0,0,0,0
#define ADV_INIT_MANU_DATA_SKIP_SEC     0,0
#define ADV_INIT_MANU_DATA_SKIP_CNT     0,0
#define ADV_INIT_MANU_DATA_SKIP_VLD_SEC 0,0

#define ADV_INIT_MANU_DATA_SCHOOL       0,0,0,0,0,0

#define ADV_SCOOL_DATA_LEN              6
#define ADV_INIT_MAC_VALID              0
#define ADV_INIT_MANU_COMPANY_DATA      ADV_INIT_MANU_DATA_HEAD, ADV_INIT_MANU_DATA_MAC, ADV_INIT_MANU_DATA_MODE, ADV_INIT_MANU_DATA_SET, ADV_INIT_MANU_DATA_UTC, ADV_INIT_MANU_DATA_SKIP_SEC, ADV_INIT_MANU_DATA_SKIP_CNT, ADV_INIT_MANU_DATA_SKIP_VLD_SEC, ADV_INIT_MAC_VALID, ADV_INIT_MANU_DATA_SCHOOL
//#define ADV_MANUFACTORY_DATA_LEN        (22+1+ADV_SCOOL_DATA_LEN)
#define ADV_MANUFACTORY_DATA_LEN        30

#define ADV_SKIP_STATE_IDLE             0
#define ADV_SKIP_STATE_SKIPING          1
#define ADV_SKIP_STATE_DONE             2

#endif  //#if(LEIJISHU == 0)

/*-----------------------------------------------------------------*/
//Custom service
#define CUS_PRO_HEAD_B1                 0xFC
#define CUS_PRO_VER_B2                  0xA0

#define CUSTOM_SERVICE_UUID             0xFFD0
#define CUSTOM_SERVICE_WRITE_UUID       0xFFD1
#define CUSTOM_SERVICE_INDICATE_UUID    0xFFD2

#define CUSTOM_IND_TIMEOUT_MS           500
#define CUSTOM_PKT_RESEND_INV_MS        2300
#define CUSTOM_TX_PKT_PAYLOAD_MAX_SIZE  (SKIP_GROUP_MAX_NUM*4 + 20 + 1)

/*-----------------------------------------------------------------*/
//File service

#define FILE_PRO_HEAD_B1                0x55
#define FILE_PRO_VER_B2                 0xA0

#define FILE_SERVICE_UUID               0xFEC0
#define FILE_SERVICE_WRITE_UUID         0xFEC1
#define FILE_SERVICE_NOTIFY_UUID        0xFEC2
#define FILE_SERVICE_DATA_UUID          0xFEC3

#define FILE_TX_PKT_PAYLOAD_MAX_SIZE    (13)
#define FILE_RX_PKT_MAX_SIZE            (BLE_MTU_MAX_SIZE - 3)

/*-----------------------------------------------------------------*/
//FONT TEXT
#define FONT_WIDTH              16
#define FONT_HEIGHT             16
#define CHAR_NUM_MAX_SIZE       30

/*-----------------------------------------------------------------*/
//Memory heap
#define LS_BLE_TOTAL_HEAP_SIZE  (3*1024)

/*-----------------------------------------------------------------*/

#endif
